function c = constrains(x)
    global Ns dmax
    [~,~,ts,Na,x,k0] = general(x);
    c=zeros(4,1);
    c(1)=sum(sum(ts,2)>dmax); % 最长飞行时间约束
    c(2)=double(k0>Ns); % k0是否大于Ns
    for i=3:Na+2
        tmp=x(i-2,:);
        c(3)=c(3)+sum(tmp~=0)-diff(find(tmp==0,2))+1; % 每一行的轨迹中间是否错误插入了D
    end
    x2=x(:)';x2(x2==0)=[];
    c(4)=double(~isequal(sort(x2),1:Ns)); % 判断是否遍历了每个监测点且无重复
end